﻿using System;
using System.Drawing;
using System.Drawing.Imaging;

namespace Simple3DRedactor.Domain
{
    [Serializable]
    public struct Texture
    {
        private readonly Bitmap _image;

        public Texture(Bitmap image)
        {
            _image = image.Clone(new Rectangle(0, 0, image.Width, image.Height), PixelFormat.Format32bppArgb);
        }

        public static bool operator == (Texture t1, Texture t2)
        {
            return t1.Equals(t2);
        }

        public static bool operator !=(Texture t1, Texture t2)
        {
            return !(t1 == t2);
        }

        public bool Equals(Texture other)
        {
            return Equals(other._image, _image);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            return obj is Texture && Equals((Texture) obj);
        }

        public override int GetHashCode()
        {
            return (_image != null ? _image.GetHashCode() : 0);
        }
    }
}
